package com.middlegroup.subjectpay.web.api;

import com.middlegroup.subjectpay.service.ChangpayService;
import com.middlegroup.subjectpay.service.HelipayService;
import com.middlegroup.subjectpay.service.KjtpayService;
import com.middlegroup.subjectpay.service.UcfpayService;
import com.middlegroup.subjectpay.service.changpay.ChangpayCallbackRequest;
import com.middlegroup.subjectpay.service.helipay.BindCardPayResponseVo;
import com.middlegroup.subjectpay.service.kjtpay.KjtpayDfCallBackRequest;
import com.middlegroup.subjectpay.service.kjtpay.KjtpayRepayCallBackRequest;
import com.middlegroup.subjectpay.service.ucfpay.CallbackRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 回调接收
 * @author pc
 * @date 2019/1/22
 */
@RestController
@RequestMapping("notify")
public class NotifyController extends BaseController {
    @Resource
    private ChangpayService changpayService;
    @Resource
    private KjtpayService kjtpayService;
    @Resource
    private UcfpayService ucfpayService;

    @Resource
    private HelipayService helipayService;


    /** 快捷通单笔代付回调
     curl -i 'http://10.0.0.109:8089/notify/kjtpayDfNotify' -d 'gmt_withdrawal=20190123122501&inner_trade_no=102154821741469860047&notify_id=01d039eecb0647e483393608c1a631bb&notify_time=20190124125040&notify_type=withdrawal_status_sync&outer_trade_no=billNo201901230006&sign=jKv8vUcy0UzbYywx8knxyopilxBLBYCE5SiYwl870ZbwZ3uGN7QeEDaycaS5dPpugKnkn3Ph2bA6o7MiBMOJSACBRWZe8ruPLQhXUYeafgZnTvkj6LYXS9TSLfKLSzccinlEuq8BwvRWqcaYd6GnQ329qD2iZaE3NqREkXe/Vd4=&sign_type=RSA&version=1.0&withdrawal_amount=0.01&withdrawal_status=WITHDRAWAL_SUCCESS'
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "kjtpayDfNotify")
    public Object kjtpayDfNotify(KjtpayDfCallBackRequest request) throws Exception {
        Object ret="";
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error("睡眠失败",e);
        }
        logger.warn("快捷通代付异步回调 enter,request:{}", request);
        ret = kjtpayService.dfNotify(request);
        logger.warn("快捷通代付异步回调 exit,response:{}", ret);
        return ret;
    }

    /** 畅捷单笔代付回调(D0,D1一样)
     curl -i 'http://10.0.0.109:8089/notify/changpayDfNotify' -d 'gmt_withdrawal=20190123122501&inner_trade_no=102154821741469860047&notify_id=01d039eecb0647e483393608c1a631bb&notify_time=20190123123810&notify_type=withdrawal_status_sync&outer_trade_no=billNo201901230006&sign=QLIc/4D6OgkZSv9F03cichIXq9g8tVUYjFEAVgcXcBJa/VCRCRExAj75+KSN87Kl3FOVIeH1nAOYJqLgnVHzUFdJqclcjs8dbAXQ6jbxGBNdGPImLUUSXBc9iZHHrvvX7rJiJsqOCv8uXbTAAVyYgt3K5Pl5Zr6UWS6e6dnWwcU=&sign_type=RSA&version=1.0&withdrawal_amount=0.01&withdrawal_status=WITHDRAWAL_SUCCESS'
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "changpayDfNotify")
    public Object changpayDfNotify(ChangpayCallbackRequest request) throws Exception {
        Object ret="";
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error("睡眠失败",e);
        }
        logger.warn("畅捷代付异步回调 enter,request:{}", request);
        ret = changpayService.dfNotify(request);
        logger.warn("畅捷代付异步回调 exit,response:{}", ret);
        return ret;
    }

    /** 畅捷单笔代扣回调(D0,D1一样)
     curl -i 'http://10.0.0.109:8089/notify/changpayDeductNotify' -d 'gmt_withdrawal=20190123122501&inner_trade_no=102154821741469860047&notify_id=01d039eecb0647e483393608c1a631bb&notify_time=20190123123810&notify_type=withdrawal_status_sync&outer_trade_no=billNo201901230006&sign=QLIc/4D6OgkZSv9F03cichIXq9g8tVUYjFEAVgcXcBJa/VCRCRExAj75+KSN87Kl3FOVIeH1nAOYJqLgnVHzUFdJqclcjs8dbAXQ6jbxGBNdGPImLUUSXBc9iZHHrvvX7rJiJsqOCv8uXbTAAVyYgt3K5Pl5Zr6UWS6e6dnWwcU=&sign_type=RSA&version=1.0&withdrawal_amount=0.01&withdrawal_status=WITHDRAWAL_SUCCESS'
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "changpayDeductNotify")
    public Object changpayDeductNotify(ChangpayCallbackRequest request) throws Exception {
        Object ret="";
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error("睡眠失败",e);
        }
        logger.warn("畅捷代扣异步回调 enter,request:{}", request);
        ret = changpayService.deductNotify(request);
        logger.warn("畅捷代扣异步回调 exit,response:{}", ret);
        return ret;
    }

    /** 畅捷协议支付回调
     curl -i 'http://10.0.0.109:8089/notify/changpayProtocolPayNotify' -d 'gmt_withdrawal=20190123122501&inner_trade_no=102154821741469860047&notify_id=01d039eecb0647e483393608c1a631bb&notify_time=20190123123810&notify_type=withdrawal_status_sync&outer_trade_no=billNo201901230006&sign=QLIc/4D6OgkZSv9F03cichIXq9g8tVUYjFEAVgcXcBJa/VCRCRExAj75+KSN87Kl3FOVIeH1nAOYJqLgnVHzUFdJqclcjs8dbAXQ6jbxGBNdGPImLUUSXBc9iZHHrvvX7rJiJsqOCv8uXbTAAVyYgt3K5Pl5Zr6UWS6e6dnWwcU=&sign_type=RSA&version=1.0&withdrawal_amount=0.01&withdrawal_status=WITHDRAWAL_SUCCESS'
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "changpayProtocolPayNotify")
    public Object changpayProtocolPayNotify(ChangpayCallbackRequest request) throws Exception {
        Object ret="";
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error("睡眠失败",e);
        }
        logger.warn("畅捷协议支付异步回调 enter,request:{}", request);
        ret = changpayService.protocolPayNotify(request);
        logger.warn("畅捷协议支付异步回调 exit,response:{}", ret);
        return ret;
    }

    /** 先锋协议支付回调
     curl -i 'http://10.0.0.109:8089/notify/ucfpayProtocolPayNotify' -d 'data='
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "ucfpayProtocolPayNotify")
    public Object ucfpayProtocolPayNotify(CallbackRequest request) throws Exception {
        Object ret="";
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error("睡眠失败",e);
        }
        logger.warn("先锋协议支付异步回调 enter,request:{}", request);
        ret = ucfpayService.protocolPayNotify(request);
        logger.warn("先锋协议支付异步回调 exit,response:{}", ret);
        return ret;
    }

    /** 快捷通协议支付回调
     curl -i 'http://10.0.0.109:8089/notify/ucfpayProtocolPayNotify' -d 'data='
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "kjtpayProtocolPayNotify")
    public Object kjtpayProtocolPayNotify(KjtpayRepayCallBackRequest request) throws Exception {
        Object ret="";
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error("睡眠失败",e);
        }
        logger.warn("快捷通协议支付异步回调 enter,request:{}", request);
        ret = kjtpayService.protocolPayNotify(request);
        logger.warn("快捷通协议支付异步回调 exit,response:{}", ret);
        return ret;
    }

    /**
     * 合利宝支付回调
     * curl -i 'http://10.0.0.109:8089/notify/helibaoDeductNotify' -d 'data='
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "helibaoDeductNotify")
    public Object helipayPayNotify(BindCardPayResponseVo request) throws Exception {
        logger.warn("合利宝支付异步回调 enter,request:{}", request);
        String ret = helipayService.deductNotify(request);
        logger.warn("合利宝支付异步回调 exit,response:{}", ret);
        return ret;
    }
}
